package com.ficus.road.maintain.ditalTwin.dao;

import com.ficus.road.maintain.core.dao.BaseMongoDao;
import com.ficus.road.maintain.core.model.digitalTwin.Asset;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
import org.springframework.data.mongodb.core.index.GeospatialIndex;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.stereotype.Component;

@Component
public class AssetDao extends BaseMongoDao<Asset, String> {

    @Override
    public String getCollectionName() {
        return "digital_asset";
    }

    @Override
    public void indexOperation() {
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("timestamp", Sort.Direction.DESC).background());
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("creation_time", Sort.Direction.DESC).background());
        GeospatialIndex geoIndex = new GeospatialIndex("location").typed(GeoSpatialIndexType.GEO_2DSPHERE);
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(geoIndex);
    }

}
